import { useState, useEffect } from 'react';
import { fetchUserTrend } from '../Employee/service';

// 考核员工走势图数据
const useUserTrend = query => {
    const [resData, setResData] = useState([]);
    const [loading, setLoading] = useState(true);

    const fetchData = async () => {
        setLoading(true);
        const { data, code } = (await fetchUserTrend(query)) || {};
        if (code === 10000) {
            setResData(data);
        }
        setLoading(false);
    };

    useEffect(() => {
        if (query.userId && query.reportType && query.startDate && query.endDate) {
            fetchData();
        }
    }, [query]);

    return [loading, resData];
};

export default useUserTrend;
